﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Partial Class bo_RequestTickets
    Inherits System.Web.UI.Page
    Public SearchBy As String
    Public SearchStr As String


    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        SearchBy = Request("reftype")
        BindDropDownList()

    End Sub

    Protected Sub BindDropDownList()
        Dim sql As New OneCall.DataModel.OneCDataEntities
        Dim ufname As List(Of OneCall.DataModel.User) = (From p In sql.Users).ToList()
        assignedTolist.DataTextField = "User_FirstName"
        assignedTolist.DataValueField = "User_FirstName"
        assignedTolist.DataSource = ufname
        assignedTolist.DataBind()
        sql.Dispose()
    End Sub
    

    Protected Sub btnShowCustDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowCustDetails.Click
        panelDetails.Visible = True

        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
       
        Dim reqId As Integer = traceTxt.Value

        


        Dim reqList As List(Of OneCall.DataModel.Request) = (From p In SQLDB.Requests Where p.Request_ID = reqId).ToList()
        Dim reqDetails As OneCall.DataModel.Request = reqList(0)

        Dim userList As List(Of OneCall.DataModel.User) = (From p In SQLDB.Users).ToList()

        'Dim userDetails As OneCall.DataModel.User  = userList(0)
        'Dim ItemList As New ArrayList()
        'ItemList.Add("Employee1")
        'ItemList.Add("Employee2")
        'ItemList.Add("Employee3")
        'ItemList.Add("Employee4")
        'ItemList.Add("Employee5")

        'assignedTolist.DataSource = ItemList

       

        lblRequestDate.Text = reqDetails.Request_Date
        lblRequestType.Text = reqDetails.Request_Type
        lblReferenceId.Text = reqDetails.Request_Reference
        lblAssignedTo.Text = reqDetails.Request_AssignedTo
        lbRequestId.Text = reqDetails.Request_ID

        If lblAssignedTo.Text <> "" Then
            assignedTolist.Visible = False
            btnAssingedTo.Visible = False
        Else
            assignedTolist.Visible = True
            btnAssingedTo.Visible = True
        End If


        If reqDetails.Request_Status = 0 Then
            lblStatus.Text = ""
            btnStatus.Visible = True
        Else
            lblStatus.Text = "Closed"
            btnStatus.Visible = False
        End If

        lblSubject.Text = reqDetails.Request_Subject
        lblDes.Text = reqDetails.Request_Description
        lblFirstName.Text = reqDetails.Request_FirstName
        lblLastName.Text = reqDetails.Request_LastName
        lblEmail.Text = reqDetails.Request_EmailID
        lblMobile.Text = reqDetails.Request_Mobile

        SQLDB.Dispose()

    End Sub

    Protected Sub btnRequestClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStatus.Click
        lblStatus.Text = "Closed"
        btnStatus.Visible = False

        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim reqId As Integer = traceTxt.Value

        Dim cRequest As OneCall.DataModel.Request = (From p In SQLDB.Requests Where p.Request_ID = reqId Select p).ToArray(0)

        cRequest.Request_Status = 1

        SQLDB.SaveChanges()
        cRequest = Nothing
        SQLDB.Dispose()

        Dim msgToAdmin As String = ""
        msgToAdmin = msgToAdmin & "Hi Admin" & "<br>"
        msgToAdmin = msgToAdmin & "<br>"
        msgToAdmin = msgToAdmin & "Service ID (" & lbRequestId.Text & ") has been closed by " & assignedTolist.SelectedValue & ".<br>" & "<br>"
        msgToAdmin = msgToAdmin & "" & "<br>"
        msgToAdmin = msgToAdmin & "==============================================" & "<br>"
        msgToAdmin = msgToAdmin & "Service request details are  here : " & "<br>"
        msgToAdmin = msgToAdmin & "Date : " & lblRequestDate.Text & "<br>"
        msgToAdmin = msgToAdmin & "Service ID (" & lbRequestId.Text & ")<br>"
        msgToAdmin = msgToAdmin & "Service Type : " & lblRequestType.Text & "<br>"
        msgToAdmin = msgToAdmin & "Service Subject : " & lblSubject.Text & "<br>"
        msgToAdmin = msgToAdmin & "Customer Full Name : " & lblFirstName.Text & " " & lblLastName.Text & "<br>"
        msgToAdmin = msgToAdmin & "Customer Email ID : " & lblEmail.Text & "<br>"
        msgToAdmin = msgToAdmin & "Customer Mobile no : " & lblMobile.Text & "<br>"
        msgToAdmin = msgToAdmin & "Description : " & lblDes.Text & "<br>"
        msgToAdmin = msgToAdmin & "==============================================" & "<br>"
        msgToAdmin = msgToAdmin & "" & "<br>"
        msgToAdmin = msgToAdmin & "Regards," & "<br>"
        msgToAdmin = msgToAdmin & "Customer service" & "<br>"
        msgToAdmin = msgToAdmin & "One Call Home Care Solution" & "<br>"
        msgToAdmin = msgToAdmin & "www.onecallhomecaresolution.com" & "<br>"

        OneCall.EmailGateway.EMailSender.SendWebEmail("chetanya_tech@yahoo.co.in", "Service ID (" & lbRequestId.Text & ") has been closed by " & assignedTolist.SelectedValue & ".", msgToAdmin)




        Dim msg As String = ""
        msg = msg & "Hi " & lblFirstName.Text & "<br>"
        msg = msg & "<br>"
        msg = msg & "Service ID (" & lbRequestId.Text & ") has been closed. <br>" & "<br>"
        msg = msg & "" & "<br>"
        msg = msg & "" & "We want to thank you on behalf of all of us here at onecallhomecaresolution for serve you our best services."
        msg = msg & "" & "<br>"
        msg = msg & "" & "<br>"
        msg = msg & "" & "<br>"
        msg = msg & "Regards," & "<br>"
        msg = msg & "Customer service" & "<br>"
        msg = msg & "One Call Home Care Solution" & "<br>"
        msg = msg & "www.onecallhomecaresolution.com" & "<br>"

        OneCall.EmailGateway.EMailSender.SendWebEmail(lblEmail.Text, "Service ID (" & lbRequestId.Text & ") has been closed.", msg)




    End Sub

    Protected Sub btnAssingedTo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAssingedTo.Click

        If assignedTolist.SelectedValue = "Select" Then
            lblAssignedTo.Text = "Select name"
            assignedTolist.Visible = True
            btnAssingedTo.Visible = True

        Else
            Dim SQLDB As New OneCall.DataModel.OneCDataEntities
            Dim reqId As Integer = traceTxt.Value

            Dim cRequest As OneCall.DataModel.Request = (From p In SQLDB.Requests Where p.Request_ID = reqId Select p).ToArray(0)

            cRequest.Request_AssignedTo = assignedTolist.SelectedValue
            lblAssignedTo.Text = assignedTolist.SelectedValue

            SQLDB.SaveChanges()
            cRequest = Nothing
            SQLDB.Dispose()

            assignedTolist.Visible = False
            btnAssingedTo.Visible = False

          

            Dim msgToAdmin As String = ""
            msgToAdmin = msgToAdmin & "Hi Admin" & "<br>"
            msgToAdmin = msgToAdmin & "<br>"
            msgToAdmin = msgToAdmin & "Service ID (" & lbRequestId.Text & ") has been assinged to " & assignedTolist.SelectedValue & ".<br>" & "<br>"
            msgToAdmin = msgToAdmin & "" & "<br>"
            msgToAdmin = msgToAdmin & "==============================================" & "<br>"
            msgToAdmin = msgToAdmin & "Service request details are  here : " & "<br>"
            msgToAdmin = msgToAdmin & "Date : " & lblRequestDate.Text & "<br>"
            msgToAdmin = msgToAdmin & "Service ID (" & lbRequestId.Text & ")<br>"
            msgToAdmin = msgToAdmin & "Service Type : " & lblRequestType.Text & "<br>"
            msgToAdmin = msgToAdmin & "Service Subject : " & lblSubject.Text & "<br>"
            msgToAdmin = msgToAdmin & "Customer Full Name : " & lblFirstName.Text & " " & lblLastName.Text & "<br>"
            msgToAdmin = msgToAdmin & "Customer Email ID : " & lblEmail.Text & "<br>"
            msgToAdmin = msgToAdmin & "Customer Mobile no : " & lblMobile.Text & "<br>"
            msgToAdmin = msgToAdmin & "Description : " & lblDes.Text & "<br>"
            msgToAdmin = msgToAdmin & "==============================================" & "<br>"
            msgToAdmin = msgToAdmin & "" & "<br>"
            msgToAdmin = msgToAdmin & "Regards," & "<br>"
            msgToAdmin = msgToAdmin & "Customer service" & "<br>"
            msgToAdmin = msgToAdmin & "One Call Home Care Solution" & "<br>"
            msgToAdmin = msgToAdmin & "www.onecallhomecaresolution.com" & "<br>"

            OneCall.EmailGateway.EMailSender.SendWebEmail("chetanya_tech@yahoo.co.in", "Service ID (" & lbRequestId.Text & ") has been assinged to " & assignedTolist.SelectedValue, msgToAdmin)



        End If

    End Sub

    Protected Sub assignedTolist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles assignedTolist.SelectedIndexChanged

    End Sub
End Class
